﻿<table width="100%"  border="0" cellpadding="3" cellspacing="1">
  <tr>
    <td><SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
//创建一个数组,用于存放每个月的天数
function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) 
{
this[0] = m0;
this[1] = m1;
this[2] = m2;
this[3] = m3;
this[4] = m4;
this[5] = m5;
this[6] = m6;
this[7] = m7;
this[8] = m8;
this[9] = m9;
this[10] = m10;
this[11] = m11;
}
//实现月历
function calendar() {
var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
var today = new Date();
var thisDay;
var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
year = today.getYear() +1900;
thisDay = today.getDate();
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29;
nDays = monthDays[today.getMonth()];
firstDay = today;
firstDay.setDate(1);
testMe = firstDay.getDate();
if (testMe == 2) firstDay.setDate(0);
startDay = firstDay.getDay();
document.write("<TABLE width='156' BORDER='0' CELLSPACING='0' CELLPADDING='0' BGCOLOR='#0080FF'>")
document.write("<TR><TD><table width='100%' border='0' cellspacing='1' cellpadding='0' bgcolor='#FFFFFF'>");
document.write("<TR><th colspan='7' bgcolor='#C8E3FF'>");
var dayNames = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var monthNames = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
var now = new Date();
document.writeln("<FONT STYLE='font-size:9pt;Color:#330099'>" + now.getYear() + "年" + monthNames[now.getMonth()] + now.getDate() + "日 " + dayNames[now.getDay()] + "</FONT>");
document.writeln("</TH></TR><TR><TH BGCOLOR='silver'><FONT STYLE='font-size:9pt;Color:White'>日</FONT></TH>");
document.writeln("<th bgcolor='silver'><FONT STYLE='font-size:9pt;Color:White'>一</FONT></TH>");
document.writeln("<TH BGCOLOR='silver'><FONT STYLE='font-size:9pt;Color:White'>二</FONT></TH>");
document.writeln("<TH BGCOLOR='silver'><FONT STYLE='font-size:9pt;Color:White'>三</FONT></TH>");
document.writeln("<TH BGCOLOR='silver'><FONT STYLE='font-size:9pt;Color:White'>四</FONT></TH>");
document.writeln("<TH BGCOLOR='silver'><FONT STYLE='font-size:9pt;Color:White'>五</FONT></TH>");
document.writeln("<TH BGCOLOR='silver'><FONT STYLE='font-size:9pt;Color:White'>六</FONT></TH>");
document.writeln("</TR><TR>");
column = 0;
for (i=0; i<startDay; i++) {
document.writeln("\n<TD><FONT STYLE='font-size:9pt'> </FONT></TD>");
column++;
}

for (i=1; i<=nDays; i++) {
if (i == thisDay) {
document.writeln("</TD><TD ALIGN='CENTER' BGCOLOR='#FF8040'><FONT STYLE='font-size:9pt;Color:#ffffff'><B>")
}
else {
document.writeln("</TD><TD BGCOLOR='#FFFFFF' ALIGN='CENTER'><FONT STYLE='font-size:9pt;font-family:Arial;font-weight:bold;Color:#330066'>");
}
document.writeln(i);
if (i == thisDay) document.writeln("</FONT></TD>")
column++;
if (column == 7) {
document.writeln("<TR>"); 
column = 0;
}
}
document.writeln("</TABLE>")
document.writeln("</TD></TR></TABLE>");
}
</SCRIPT>
      <SCRIPT language=JavaScript>

<!--


tg=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
dz=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");
sx=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪");
w=new Array("木","火","土","金","水");
f=new Array("东","南","中","西","北");
sz=new Array("一","二","三","四","五","六","七","八","九","十",
"十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
"廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十");
m0=new Array(
0,1,0,0,1,0,1,0,1,1,1,0,1,0,1,0,0,1,0,1,0,1,1,1,//1901
0,1,0,1,2,1,0,0,1,1,0,1,1,1,0,1,0,0,1,0,0,1,1,0,
1,1,0,1,1,0,0,1,0,1,0,1,0,1,1,3,0,1,0,1,0,1,0,1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,1,0,1,1,1,0,1,0,1,0,0,1,0,0,1,1,1,0,
1,1,0,1,0,0,1,0,0,1,1,0,1,1,1,0,4,0,1,0,0,1,1,0,
1,1,0,1,0,1,0,1,0,0,1,1,0,1,0,1,1,0,1,0,1,0,1,0,47455)
m13=new Array(
0,1,4,1,0,1,1,0,1,0,1,0,1,0,0,1,0,1,1,0,1,1,0,1,//2031
0,1,0,0,1,0,1,0,1,1,4,1,0,1,0,0,1,0,1,0,1,1,0,1,
1,0,1,0,0,1,0,0,1,1,0,1,1,1,0,1,0,3,0,0,1,0,1,1,
1,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,0,
1,1,0,1,4,1,0,1,0,1,0,0,1,0,1,1,0,1,0,1,1,0,1,0,51117)
m14=new Array(
0,1,0,1,0,1,1,0,1,1,0,1,0,4,0,1,0,1,0,1,1,0,1,1,//2041
0,1,0,0,1,0,0,1,1,0,1,1,1,0,1,0,0,1,2,1,0,1,1,1,
1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,0,1,0,1,0,0,1,0,1,
1,0,1,1,3,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,0,0,1,0,
1,0,1,0,1,1,0,1,1,0,1,0,0,1,3,0,1,0,1,1,0,1,1,0,54779)
ms=new Array(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14);
ly=new Array(29,30,58,59,59,60);
tw=new Array(0,0,1,1,2,2,3,3,4,4);
dw=new Array(4,2,0,0,2,1,1,2,3,3,2,4);

function inq(form){
 re="请重新输入！";
 y=form.y.value;
 if (y==""||y<1901||y>2050)
  alert("年应在1901和2050之间。"+re);
 else{
  gl0=(Date.UTC(y,0,1)-Date.UTC(1901,1,19))/86400000;
  dy=y-1901;
  i=Math.floor(dy/10);
  nl0=(i==0)?0:ms[i-1][120];
  n=i*120;
  for (j=0;j<120;j++){
   n++;
   if (n>dy*12) break;
   nl0+=ly[ms[i][j]];
  }
  cjr=(nl0-gl0)%31+1;
  cjy=(nl0-gl0>30)?2:1;
  jq=tg[(dy+6)%10]+dz[dy%12];
  jh=tg[(dy+7)%10]+dz[(dy+1)%12];
  s1="<title>查询结果</title><body bgcolor=#F5E7A9 text=#ff0000><center>"+
   "<table width=400><tr><td><font size=4>　　　查询结果<p>公历："+y+"年";
  s2="<br>春节："+cjy+"月"+cjr+"日<br>节前："+jq+"年<br>节后："+jh+"年<br>";
  s3="查询生辰八字，请输入时。";
  s4="</font></td></tr></table></center></body>";
  m=form.m.value;
  d=form.d.value;
  h=form.h.value;
  if (m==""||d==""){
   document.write(s1,s2,"<br>","进一步查询，请输入月和日。<br>",s3,s4);
   document.close();
  }
  else if (m>12||m<1)
   alert("月应在1与12之间。"+re);
  else if (d>31||d<1)
   alert("日应在1与31之间。"+re);
  else if ((m==4||m==6||m==9||m==11)&&d>30)
   alert(m+"月只有30天。"+re);
  else if (y%4!=0&&m==2&&d>28)
   alert(y+"年是平年，2月只有28天。"+re);
  else if (m==2&&d>29)
   alert(y+"年是闰年，2月只有29天。"+re);
  else if (h>23||h<0)
   alert("时应在0与23之间。"+re);
  else{
   if (form.h.value=="") h=0;
   sum=(Date.UTC(y,m-1,d,h)-Date.UTC(1901,1,18,23))/1000;
   sumd=Math.floor(sum/86400);
   day=(Math.floor((sum-1800)/86400)+51)%7;
   xq=(day==0)?"日":sz[day-1];
   tgr=(sumd+54)%10;
   dzr=(sumd+52)%12;
   gzr=tg[tgr]+dz[dzr];
   dzs=Math.floor((h*1+1)/2)%12;
   tgs=((tgr%5)*2+dzs)%10;
   gzs=tg[tgs]+dz[dzs];
   for (i=0;ms[i][120]<=sumd;i++);
   k=(i==0)?0:ms[i-1][120];
   p=i*120;
   for (j=0;j<120;j++){
    k+=ly[ms[i][j]];
    p++;
    if (k>sumd) break;
   }
   if (sumd+30<0){
    ri=59+sumd;
    p=-1;
   }
   else if (sumd<0){
    ri=30+sumd;
    p=0;
   }
   else
    ri=sumd+ly[ms[i][j]]-k;
   yue=((p+11)%12==0)?"正":sz[(p+11)%12];
   mij=ms[i][j];
   if ((mij==2||mij==3)&&ri>28){
    ri-=29;
    yue="闰"+yue;
   }
   else if ((mij==4||mij==5)&&ri>29){
    ri-=30;
    yue="闰"+yue;
   }
   ri=((ri<10)?"初":"")+sz[ri];
   tgn=Math.floor((p-1)/12+7)%10;
   dzn=Math.floor((p-1)/12+1)%12;
   gzn=tg[tgn]+dz[dzn];
   tgy=(p+5)%10;
   dzy=(p+1)%12;
   gzy=tg[tgy]+dz[dzy];
   tn=tw[tgn];
   dn=dw[dzn];
   ty=tw[tgy];
   dy=dw[dzy];
   tr=tw[tgr];
   dr=dw[dzr];
   ts=tw[tgs];
   ds=dw[dzs];
   s5=m+"月"+d+"日（星期"+xq+"）";
   s6="<br>农历："+gzn+"年"+yue+"月"+ri+"日";
   s7="生肖："+sx[dzn]+"<p>"
   if (form.h.value=="")
    document.write(s1,s5,s6,s2,"干支：",gzn,"年",gzy,"月",gzr,"日<br>",s7,s3,s4);
   else
    document.write(s1,s5,h,"点",s6,dz[dzs],"时",s2,
    "八字：",gzn,"　",gzy,"　",gzr,"　",gzs,"<br>",
    "五行：",w[tn],w[dn],"　",w[ty],w[dy],"　",w[tr],w[dr],"　",w[ts],w[ds],"<br>",
    "方位：",f[tn],f[dn],"　",f[ty],f[dy],"　",f[tr],f[dr],"　",f[ts],f[ds],"<br>",s7,s4);
   document.close();
  }
 }
}
function setfocus(){
 document.cal.y.focus();
 return;
}
//-->

  </SCRIPT>
      <FORM name=cal target="_blank" method="post">
        <INPUT maxLength=4 size=12 name=y>
        请输入年（1901—2050）
        <P>
          <INPUT maxLength=2 size=12 name=m>
          请输入月（1—12） 
        <P>
          <INPUT maxLength=2 size=12 name=d>
          请输入日（1—31） 
        <P>
          <INPUT maxLength=2 size=12 name=h>
          请输入时（0—23）<font size="3"> </font>
        <P align="left"> <font size="3">
          <INPUT name="button" type=button onclick=inq(cal) value=查询 class="button1">
          <INPUT name="reset" type=reset value=清除 class="button1">
          </font>
      </FORM></td>
  </tr>
</table>
